package com.ruoyi.demo.controller.app;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.demo.domain.AuctionDeposit;
import com.ruoyi.demo.service.IAuctionDepositService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 竞拍保证金控制器（APP端）
 *
 * @author WangJiang
 * @date 2025/02/25
 */
@Api(tags = "小程序-保证金管理")
@RestController
@RequestMapping("/app/deposit")
@RequiredArgsConstructor
public class AppAuctionDepositController extends BaseController {

    private final IAuctionDepositService depositService;

    /**
     * 分页查询保证金记录
     */
    @ApiOperation("保证金分页列表")
    @GetMapping("/list")
    public TableDataInfo list(AuctionDeposit deposit) {
        startPage();
        List<AuctionDeposit> list = depositService.selectAuctionDepositList(deposit);
        return getDataTable(list);
    }

    /**
     * 支付保证金
     */
    @ApiOperation("支付保证金")
    @Log(title = "保证金支付", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping("/pay")
    public AjaxResult payDeposit(@RequestBody AuctionDeposit deposit) {
        return toAjax(depositService.payDeposit(deposit));
    }

    /**
     * 处理保证金退款
     */
    @ApiOperation("保证金退款")
    @Log(title = "保证金退款", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PostMapping("/refund/{depositId}")
    public AjaxResult refundDeposit(@PathVariable Long depositId) {
        return toAjax(depositService.refundDeposit(depositId));
    }

    /**
     * 获取保证金详细信息
     */
    @ApiOperation("保证金详情")
    @GetMapping(value = "/{depositId}")
    public AjaxResult getInfo(@PathVariable("depositId") Long depositId) {
        return success(depositService.selectAuctionDepositByDepositId(depositId));
    }

    /**
     * 删除保证金记录
     */
    @ApiOperation("删除保证金记录")
    @Log(title = "保证金记录删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{depositIds}")
    public AjaxResult remove(@PathVariable Long[] depositIds) {
        return toAjax(depositService.deleteAuctionDepositByDepositIds(depositIds));
    }

    /**
     * 导出保证金记录
     */
    @ApiOperation("导出保证金记录")
    @Log(title = "保证金记录导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionDeposit deposit) {
        List<AuctionDeposit> list = depositService.selectAuctionDepositList(deposit);
        ExcelUtil<AuctionDeposit> util = new ExcelUtil<>(AuctionDeposit.class);
        util.exportExcel(response, list, "保证金记录");
    }
}
